/*
 * Copyright (c) 2017 Qunar.com. All Rights Reserved.
 */
package com.guoyu.project.web.admin;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.guoyu.project.common.constant.Constants;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.guoyu.project.model.Manager;

/**
 * @author: libo Date: 17-3-23 Time: 下午1:57
 * @version: \$Id$
 */
public class BaseController {

    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        /**
         * 自动转换日期类型的字段格式
         */
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
    }

    public static Manager getManager(HttpServletRequest request) {
        return (Manager) request.getSession().getAttribute(Constants.MANAGER_SERSSION);
    }

    public static void setManager(HttpServletRequest request, Manager manager) {
        request.getSession().setAttribute(Constants.MANAGER_SERSSION, manager);
    }
}
